﻿using LdtDataEngin.ModuleDetail.PersonnelAnalysis.PersonnelModel.Interface;
using LdtJudge.DataEngine.Common.CommHelp;
using LdtJudge.DataEngine.Model.Personnel;
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace LdtDataEngin.ModuleDetail.PersonnelAnalysis.PersonnelModel.Determine
{
    public class B1Determine : IDetermine
    {
        /// <summary>
        /// 民事一审当事人代称处理
        /// </summary>
        /// <param name="Pre"></param>
        /// <param name="Name"></param>
        /// <param name="spIndex"></param>
        /// <param name="mcs"></param>
        /// <returns></returns>
        public bool IsMatchAccusedOrProsecutor(string Pre, string Name, string spIndex, ElementSpokeName mcs)
        {

            try
            {
                if (string.IsNullOrEmpty(Name))
                {
                    return false;
                }
                string FirstName = Name == "" ? "" : Name.Substring(0, 1);
                ChnNumFormat chnum = new ChnNumFormat();
                string[] AllMatchStr = new string[] { Pre, spIndex + Pre, Pre + spIndex + "(?=$)", chnum.NumToChn(spIndex) + Pre, Pre + chnum.NumToChn(spIndex) + "(?=$)", Pre + "告" + chnum.NumToChn(spIndex) + "(?=$)", Pre + "告" + spIndex + "(?=$)", Pre + FirstName, Pre + "告(?=$)", "^" + FirstName, "^" + Name, "第" + chnum.NumToChn(spIndex) + Pre + "告", "^" + FirstName + "(?=$)" };
                string RegStr = string.Join("|", AllMatchStr);
                if (string.IsNullOrEmpty(mcs.ES_FullName))
                {
                    MatchCollection matches = new Regex(RegStr).Matches(mcs.ES_ShortName);
                    if (matches.Count < 2)
                    {
                        return new Regex(RegStr).IsMatch(mcs.ES_ShortName);
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(mcs.ES_FullName) && mcs.ES_RoleIndex == spIndex)
                        {
                            return new Regex(RegStr).IsMatch(mcs.ES_ShortName);
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
                else
                {
                    return false;
                }
            }
            catch (System.Exception)
            {

                return false;
            }
        }
        /// <summary>
        /// 民事二审代理人代称处理
        /// </summary>
        /// <param name="Pre"></param>
        /// <param name="Mid"></param>
        /// <param name="Name"></param>
        /// <param name="spIndex"></param>
        /// <param name="mcs"></param>
        /// <param name="ProxyName"></param>
        /// <returns></returns>
        public bool IsMatchProxy(string Pre, string Mid, string Name, string spIndex, ElementSpokeName mcs, string ProxyName = "")
        {
            try
            {
                if (string.IsNullOrEmpty(Name))
                {
                    return false;
                }

                string ProxyFirstName = ProxyName.Substring(0, 1);
                string FirstName = Name.Substring(0, 1);
                string ending = "代";
                ChnNumFormat chnum = new ChnNumFormat();
                List<string> AllMatchStr = new List<string> { spIndex + Pre + ending, Pre + spIndex + ending, chnum.NumToChn(spIndex) + Pre + ending, Pre + chnum.NumToChn(spIndex) + ending, Pre + FirstName + ending, Pre + Mid + ending + "(?=$)", Pre + Mid + ending + ProxyFirstName + "(?=$)", Pre + ending + "(?=$)", "^" + ProxyName, "^" + ProxyFirstName + "(?=$)", Pre + ending + ProxyFirstName };

                if (!string.IsNullOrEmpty(ProxyName))
                {
                    //AllMatchStr.Add(ProxyName);
                }
                string RegStr = string.Join("|", AllMatchStr);
                if (string.IsNullOrEmpty(mcs.ES_FullName))
                {
                    MatchCollection matches = new Regex(RegStr, RegexOptions.Singleline).Matches(mcs.ES_ShortName);
                    if (matches.Count < 2)
                    {
                        return new Regex(RegStr).IsMatch(mcs.ES_ShortName);
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(mcs.ES_FullName) && mcs.ES_RoleIndex == spIndex)
                        {
                            return new Regex(RegStr).IsMatch(mcs.ES_ShortName);
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
                else
                {
                    return false;
                }
            }
            catch (System.Exception)
            {
                return false;
            }
        }
    }
}
